package com.chenyi.web.controller.system;

import com.chenyi.common.annotation.Log;
import com.chenyi.common.core.controller.BaseController;
import com.chenyi.common.core.page.TableDataInfo;
import com.chenyi.common.enums.BusinessType;
import com.chenyi.common.utils.poi.ExcelUtil;
import com.chenyi.system.domain.SysAdver;
import com.chenyi.system.service.ISysAdverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 广告管理Controller
 * 
 * @author qinggeng
 * @date 2020-02-12
 */
@RestController
@RequestMapping("/admin/adver")
public class AdminAdverController extends BaseController
{
    @Autowired
    private ISysAdverService adverService;

    /**
     * 查询广告管理列表
     */
    @PreAuthorize("@admin.hasPermi('system:adver:list')")
    @GetMapping("/list")
    public ResponseEntity<TableDataInfo> list(SysAdver adver)
    {
        startPage();
        List<SysAdver> list = adverService.selectSysAdverList(adver);
        return new ResponseEntity<>(getDataTable(list),HttpStatus.OK);
    }

    /**
     * 导出广告管理列表
     */
    @PreAuthorize("@admin.hasPermi('system:adver:export')")
    @Log(title = "广告管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<Object> export(SysAdver adver)
    {
        List<SysAdver> list = adverService.selectSysAdverList(adver);
        ExcelUtil<SysAdver> util = new ExcelUtil<SysAdver>(SysAdver.class);
        return util.exportExcel(list, "adver");
    }

    /**
     * 获取广告管理详细信息
     */
    @PreAuthorize("@admin.hasPermi('system:adver:query')")
    @GetMapping(value = "/{adverId}")
    public ResponseEntity<Object> getInfo(@PathVariable("adverId") Long adverId)
    {
        return ResponseEntity.ok(adverService.selectSysAdverById(adverId));
    }

    /**
     * 新增广告管理
     */
    @PreAuthorize("@admin.hasPermi('system:adver:add')")
    @Log(title = "广告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Object> add(@RequestBody SysAdver adver)
    {
        adverService.insertSysAdver(adver);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    /**
     * 修改广告管理
     */
    @PreAuthorize("@admin.hasPermi('system:adver:edit')")
    @Log(title = "广告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Object> edit(@RequestBody SysAdver adver)
    {
        adverService.updateSysAdver(adver);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    /**
     * 删除广告管理
     */
    @PreAuthorize("@admin.hasPermi('system:adver:remove')")
    @Log(title = "广告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adverIds}")
    public ResponseEntity<Object> remove(@PathVariable Long[] adverIds)
    {
        adverService.deleteSysAdverByIds(adverIds);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
